
<template>
  <div>
    <MyHeader title="购物车案例" color='' bgc='darkgreen'/>
    <div class="main">
      <!-- 渲染页面 -->
      <MyGoods v-for='item in list' :key="item.id" :good='item' />
    </div>
       <MyFooter :list ='list'/>
  </div>
</template>

<script>
import MyHeader from './components/MyHeader.vue'
import MyFooter from './components/MyFooter.vue'
import MyGoods from './components/MyGoods.vue'
export default {
  data(){
    return{
      list:[] // 商品所有数据
    }
  },
  //请求数据
  created(){
    this.$axios({
    //请求地址
      url:"/api/cart"
    }).then(res =>{
      //将请求到数据中的数组传入this.list中
      this.list =res.data.list
      console.log(this.list);
    }).catch(err =>{
      //捕捉错误
      console.log(err);
    })
  },
  components:{
    MyHeader,
    MyFooter,
    MyGoods,
  }
}
</script>

<style>
.main{
    padding-top: 45px;
    padding-bottom: 50px;
  }
</style>